﻿(function () {
    function e(e) {
        e = e || event;
        var t = e.target || e.srcElement,
			n, r, i, s = 0,
			o;
        for (var u = 0, a; a = v[u++];) if (a.contains ? a.contains(t) : !!(a.compareDocumentPosition(t) & 16)) {
            r = a.id;
            break
        }
        if (/^(A|IMG)$/.test(t.tagName)) {
            if (t.tagName == "IMG") {
                i = t, t = t.parentNode;
                if (t.tagName != "A") return
            }
            o = t.getAttribute("text") || t.innerHTML, w("http://haostat.qihoo.com/haoclk.gif?t=" + +(new Date) + "&u=" + d(c) + "&f=" + d(t.href) + "&c=" + d(i ? i.src.match(/[^\/]+$/) : o) + "&cId=" + r + "&id=" + m + "&guid=" + g)
        } else {
            if (t.tagName == "BUTTON" && t.type == "submit" || t.tagName == "INPUT" && t.type == "submit") {
                if (t.id == "searchBtn" || t.id == "search-btn") n = A ? A.value : "";
                while (t = t.parentNode) if (t.tagName == "FORM") {
                    t.id == "search-form" || t.id == "searchForm" ? E("u=" + d(c) + "&w=" + d(n) + "&f=" + d(t.action) + "&c=form:" + (t.name || t.id) + "&cId=" + r + "&id=" + m + "&guid=" + g) : E("u=" + d(c) + "&f=" + d(t.action) + "&c=form:" + (t.name || t.id) + "&cId=" + r + "&id=" + m + "&guid=" + g);
                    break
                }
                return
            }
            if (t.tagName == "AREA") {
                w("http://haostat.qihoo.com/haoclk.gif?t=" + +(new Date) + "&u=" + d(c) + "&f=" + d(t.href) + "&c=area:" + d(t.parentNode.name) + "&cId=" + r + "&id=" + m + "&guid=" + g);
                return
            }
            while (t = t.parentNode) {
                if (s++ > 3) return;
                if (t.tagName == "A") {
                    o = t.getAttribute("text") || t.innerHTML, w("http://haostat.qihoo.com/haoclk.gif?t=" + +(new Date) + "&u=" + d(c) + "&f=" + d(t.href) + "&c=" + d(o) + "&cId=" + r + "&id=" + m + "&guid=" + g);
                    break
                }
            }
        }
    }
    function t(e) {
        e = arguments[0] || event;
        var t = e.target || e.srcElement,
			n, r;
        for (var i = 0, s; s = v[i++];) if (s.contains ? s.contains(t) : !!(s.compareDocumentPosition(t) & 16)) {
            n = s.id;
            break
        }
        if (e.keyCode == 13) {
            if (t.id == "kw" || t.id == "search-kw" || t.id == "kw1") r = t.value;
            if (t.tagName == "INPUT") while (t = t.parentNode) if (t.tagName == "FORM") {
                t.id == "search-form" || t.id == "searchForm" ? E("u=" + d(c) + "&w=" + d(r) + "&f=" + d(t.action) + "&c=form:" + (t.name || t.id) + "&cId=" + n + "&id=" + m + "&guid=" + g) : E("u=" + d(c) + "&f=" + d(t.action) + "&c=form:" + (t.name || t.id) + "&cId=" + n + "&id=" + m + "&guid=" + g);
                break
            }
        }
    }
    window.logimgs = {};
    var n = function (e) {
        var t = new RegExp("(\\?|#|&)" + e + "=([^&#]*)(&|#|$)"),
            n = (document.location + "").match(t);
        return n ? n[2] : ""
    },
		r = window,
		i = window.screen,
		s = document,
		o = s.cookie,
		u = s.referrer,
		a = s.domain.toLowerCase(),
		f = navigator,
		l = f.userAgent.toLowerCase(),
		c = location.href.split("?")[0],
		h = n("ls"),
		p, d = encodeURIComponent,
		v = [],
		m, g, y, b = {
		    "360se-ua": "360se",
		    "360ee": "360ee",
		    TT: "tencenttraveler",
		    Maxthon: "maxthon",
		    GreenBrowser: "greenbrowser",
		    Sogou: "se 1.x / se 2.x",
		    TheWorld: "theworld"
		},
		w = function (e) {
		    var t = "log_" + (new Date).getTime(),
				n = window.logimgs[t] = new Image;
		    n.onload = n.onerror = function () {
		        window.logimgs[t] = null, delete window.logimgs[t]
		    }, h && (e += "&ls=" + h), n.src = e
		},
		E = function () {
		    var e = "";
		    return function (t) {
		        if (t === e) return;
		        e = t, w("http://haostat.qihoo.com/haoclk.gif?t=" + +(new Date) + "&" + t), setTimeout(function () {
		            e = ""
		        }, 500)
		    }
		}(),
		S = function () {
		    if (window.hao360 && hao360.is360se) {
		        if (hao360.is360se()) return "360se";
		        if (hao360.is360se6()) return "360se6";
		        if (hao360.is360ee()) return "360ee"
		    }
		    for (var e in b) if (l.indexOf(b[e]) > -1) return e;
		    var t = l.match(/(msie|chrome|safari|firefox|opera|trident)/);
		    return t = t ? t[0] : "", t == "msie" ? t = l.match(/msie[^;]+/) + "" : t == "trident" && l.replace(/trident\/[0-9].*rv[ :]([0-9.]+)/ig, function (e, n) {
		        t = "msie " + n
		    }), t
		},
		x = function (e) {
		    var t = 0,
				n = 0;
		    for (var r = e.length - 1; r >= 0; r--) {
		        var i = parseInt(e.charCodeAt(r));
		        t = (t << 6 & 268435455) + i + (i << 14), (n = t & 266338304) != 0 && (t ^= n >> 21)
		    }
		    return t
		},
		T = function () {
		    var e = [f.appName, f.version, f.language || f.browserLanguage, f.platform, f.userAgent, i.width, "x", i.height, i.colorDepth, s.referrer].join(""),
				t = e.length,
				n = history.length;
		    while (n > 0) e += n-- ^ t++;
		    return (Math.round(Math.random() * 2147483647) ^ x(e)) * 2147483647
		},
		N = function () {
		    var e = o.match(/count=(\d+)/),
				t = +C.get("count") || 0;
		    return t++, C.set("count", t, {
		        expires: 864e5
		    }), t
		},
		C = {
		    getRaw: function (e) {
		        var t = new RegExp("(^| )" + e + "=([^;]*)(;|$)"),
					n = t.exec(document.cookie);
		        return n ? n[2] || null : null
		    },
		    get: function (e) {
		        var t = C.getRaw(e);
		        return "string" == typeof t ? (t = decodeURIComponent(t), t) : null
		    },
		    setRaw: function (e, t, n) {
		        n = n || {};
		        var r = n.expires;
		        "number" == typeof n.expires && (r = new Date, r.setTime(r.getTime() + n.expires)), document.cookie = e + "=" + t + (n.path ? "; path=" + n.path : "") + (r ? "; expires=" + r.toGMTString() : "") + (n.domain ? "; domain=" + n.domain : "") + (n.secure ? "; secure" : "")
		    },
		    set: function (e, t, n) {
		        C.setRaw(e, encodeURIComponent(t), n)
		    },
		    remove: function (e, t) {
		        t = t || {}, t.expires = new Date(0), C.setRaw(e, "", t)
		    }
		};
    p = N(), m = C.get("sessionID"), y = C.get("__guid"), m || (m = [x(a), T(), +(new Date) + Math.random() + Math.random()].join("."), C.set("sessionID", m, {
        expires: 864e5
    }));
    if (!y) {
        g = C.get("guid"), g ? (y = g, C.remove("guid")) : y = [x(a), T(), +(new Date) + Math.random() + Math.random()].join(".");
        var k = {
            expires: 432e8,
            path: "/"
        },
			L = "360.cn";
        if (a.indexOf(L) > 0 && a.lastIndexOf(L) == a.length - L.length || a === L) k.domain = "." + L;
        C.set("__guid", y, k)
    }
    g = y, c = /\.(s?htm|php)/.test(c) ? c : c.replace(/\/$/, "") + "/index.html";
    var A = s.getElementById("kw") || s.getElementById("search-kw") || s.getElementById("kw1");
    s.attachEvent ? s.attachEvent("onclick", e) : s.addEventListener("click", e, !1), s.attachEvent ? s.attachEvent("onkeydown", t) : s.addEventListener("keydown", t, !1), window.moniter = {
        setUrl: function (e) {
            return e && (c = e), this
        },
        getTrack: function (e) {
            return w("http://haostat.qihoo.com/haopv.gif?b=" + S() + "&a=" + (e === undefined ? 1 : e) + "&u=" + d(c) + "&id=" + m + "&c=" + p + "&r=" + d(u) + "&t=" + +(new Date)), w("http://haostat.qihoo.com/haouv.gif?b=" + S() + "&a=" + (e === undefined ? 1 : e) + "&u=" + d(c) + "&id=" + g + "&c=" + p + "&r=" + d(u) + "&t=" + +(new Date)), this
        },
        setId: function (e) {
            for (var t = 0, n; n = e[t++];) n = document.getElementById(n), n && v.push(n);
            return this
        }
    }
})();